<?php
namespace Systemht\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $config = M('Config')->where(array('id'=>1))->find();
        $this->assign('config',$config);
        $this->display();
    }
    public function _initialize(){
    	$uname = session('uname_admin');
    	if(empty($uname)){
    		$this->redirect('Login/index');
    	}
    }
    public function logout(){
    	session(null);
    	$this->success('退出成功',U('Index/login'));
    }
    public function changepwd(){
        $oldpassword = I('post.old_password');
        if(empty($oldpassword)){
            $this->error('请填写原密码');
        }
        $password = I('post.password');
        if(empty($password)){
            $this->error('请填写新密码');
        }
        $repassword = I('post.repassword');
        if($password != $repassword){
            $this->error('重复密码不正确');
        }
        $model = M('Admin');
        $info = $model->where(array('id'=>session('uid_admin')))->find();
        if($info['password'] == md5($oldpassword)){
            if(false !== $model->where(array('id'=>session('uid_admin')))->setField('password',md5($password))){
                $this->success('修改成功',U('Config/index'));
                exit;
            }
        }
        else{
            $this->error('原密码不正确');
        }

    }
}